package com.tom.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tom.util.JDBCUtil;

/***
 * 将json数据整理落表
 * @author Tom
 *
 */
public class JDDataTransferImpl {
	
	public static void main(String[] args){
		try {
			ArrayList<String> list =  JDBCUtil.getJDJson();
			for(int i = 0 ; i < list.size() ; i ++){
				System.err.println("----------"+i);
				JSONObject json = JSON.parseObject(list.get(i));
				JSONArray comments = json.getJSONArray("comments");
				ArrayList<String> commentResult = new ArrayList<String>();
				ArrayList<String> scoreResult = new ArrayList<String>();
				for(int j = 0 ; j < comments.size() ; j++){
					String comment = ((JSONObject)comments.get(j)).getString("content");
					String score = ((JSONObject)comments.get(j)).getString("score");
					commentResult.add(comment);
					scoreResult.add(score);
				}
				JDBCUtil.JDJsonTransfer(commentResult, scoreResult, "jd_comment_detail");
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
